package com.angel.provider.health.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.angel.core.base.BaseProviderImpl;
import com.angel.core.util.Pager;
import com.angel.dao.health.BuzCustomerMapper;
import com.angel.dao.health.BuzVideoMapper;
import com.angel.health.BuzCustomer;
import com.angel.health.BuzDoctorWorkLog;
import com.angel.health.BuzVideo;
import com.angel.health.ln.ChartMap;
import com.angel.provider.health.BuzCustomerProvider;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

@Service
public class BuzCustomerProviderImpl extends BaseProviderImpl<BuzCustomer> implements BuzCustomerProvider{

	@Autowired
	BuzCustomerMapper customerMapper;
	@Autowired
	BuzVideoMapper bvMapper;
	
	public List<Map<String, Object>> findCustomerByPhone(BuzCustomer buzCustomer) {
		BuzCustomer bc= new BuzCustomer();
		if(buzCustomer.getMemPhone() != null && buzCustomer.getMemPhone() != ""){
			bc.setMemPhone(buzCustomer.getMemPhone());
		}
		return customerMapper.findCustomerList(bc);
	}
	
	@Override
	public int insert(BuzCustomer record) {
		Date date = new Date();
		record.setCreateTime(date);
		record.setUpdateTime(date);
		record.setEnable(1);
		int insert = customerMapper.insert(record);
		if(insert > 0){
			BuzVideo bv = new BuzVideo();
			bv.setVideoMinutes(10);
			bv.setCustomerId(record.getId());
			bv.setCreateTime(new Date());
			bvMapper.insert(bv);
		}
		return insert;
	}

	@Override
	public List<Map<String, Object>> findCustomerList(BuzCustomer buzCustomer) {
		// TODO Auto-generated method stub
		return customerMapper.findCustomerList(buzCustomer);
	}

	@Override
	public List<Map<String, Object>> findCustomerByUser(String user) {
		// TODO Auto-generated method stub
		return customerMapper.findCustomerByUser(user);
	}

	@Override
	public BuzCustomer getById(Integer id) {
		// TODO Auto-generated method stub
		return customerMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<BuzCustomer> findAllCustomer(BuzCustomer customer) {
		return customerMapper.findAllCustomer(customer);
	}

	@Override
	public List<ChartMap> loadChart() {
		// TODO Auto-generated method stub
		return customerMapper.loadChart();
	}

	@Override
	public List<Map<String, Object>> docCus(BuzDoctorWorkLog bdwl) {
		// TODO Auto-generated method stub
		return customerMapper.docCus(bdwl);
	}

	@Override
	public Pager selectCustomerByBep(BuzCustomer customer,Pager pager) {
		// TODO Auto-generated method stub
		PageHelper.startPage(pager.getCurrentPage(), pager.getPageSize());
		List<Map<String,Object>> list = customerMapper.selectCustomerByBep(customer);
		PageInfo<Map<String, Object>> pageInfo = new PageInfo<Map<String, Object>>(list);
		pager.setTotal(pageInfo.getTotal());
		pager.setTotalPages(pageInfo.getPages());
		pager.setList(pageInfo.getList());
		
		return pager;
	}

}
